package enum05;

import org.junit.Test;

import java.lang.reflect.Method;

/**
 *
 * Java中所有用enum定义的枚举默认会继承一个类:java.lang.Enum
 * Class类中的方法:
 *   Class<? super T> getSuperclass()
 *          获取该字节对象的父字节码对象
 *    Method[] getMethods()
 *         获取该字节码对象中所有public修饰的成员方法
 *
 * 枚举中的常用方法:
 *   public static Week[] values()
 *      获取所有的枚举常量,并把所有的枚举常量封装到一个数组返回
 *   public static Week valueOf(String str)
 *   public final String name()返回此枚举常量的名称，在其枚举声明中对其进行声明
 */
public class WeekDemo {
    @Test
    public void testMethod01(){
        System.out.println(Week.class.getSuperclass()); // class java.lang.Enum
    }

    @Test
    public void testMethod02(){
        //1.利用字节码对象获取所有成员犯法
        Method[] methods = Week.class.getMethods();

        // 2.遍历method数组
        for (Method method : methods) {
            System.out.println(method);
        }
    }

    @Test
    public void testMethod03(){
        Week[] values = Week.values();
        for (Week value : values) {
            System.out.println(value);
           // MONDAY
            //TUESDAY
            //WEDNESDAY
            //THURSDAY
            //FRIDAY
            //SATURDAY
            //SUNDAY
        }
    }

    @Test
    public void testMethod04(){
        System.out.println(Week.valueOf("MONDAY")); // MONDAY
        System.out.println(Week.valueOf("MONDAY") == Week.MONDAY); // true
        // 说明两个是同一个对象
    }

    @Test
    public void testMethod05(){
        System.out.println(Week.FRIDAY.name());
        System.out.println(Week.FRIDAY);
        System.out.println(Week.FRIDAY.toString());
        // 和toString原理相同
    }
}
